import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import dts from 'vite-plugin-dts'

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  if (mode === 'lib') {
    // 库构建配置
    return {
      plugins: [
        vue(),
        dts({
          outDir: 'dist',
          include: ['src/**/*'],
          exclude: ['src/main.ts', 'src/vite-env.d.ts']
        })
      ],
      build: {
        lib: {
          entry: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
          name: 'PhoneUIVue',
          fileName: 'phone-ui-vue'
        },
        rollupOptions: {
          external: ['vue'],
          output: {
            globals: {
              vue: 'Vue'
            }
          }
        },
        cssCodeSplit: false,
        // 不生成单独的 CSS 文件，样式内联在 JS 中
        cssTarget: 'chrome61'
      }
    }
  }
  
  // 开发模式配置
  return {
    plugins: [vue()],
  }
})
